<?php
/* RSS News reader plugin for Textcube 1.6
	----------------------------------
   Version 1.6
   Tatter Network Foundation development team / Needlworks

   Creator          : Peris

   Created at       : 0000.00.00
   Last modified at : 2008.02.25
 
This plugin keeps original permalink.
For the detail, visit http://forum.tattersite.com/ko

General Public License
http://www.gnu.org/licenses/gpl.html

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/

include_once("RSSNews.php");

function SB_RSSNews($parameters = array()) {
	global $database, $blogid, $pluginURL;
	$category	= $parameters['category'] ? $parameters['category'] : 'RSSNews';	//카테고리(리더)
	$number		= $parameters['number'] ? $parameters['number'] : 5;				//갯수
	$title		= $parameters['title'] ? $parameters['title'] : '<h3>RSS News</h3>';//제목
	$reload		= $parameters['reload'] ? $parameters['reload'] : '-30';			//새로고침 위치

	$query = "SELECT
					c.xmlURL
				FROM
					{$database['prefix']}FeedGroups a,
					{$database['prefix']}FeedGroupRelations b,
					{$database['prefix']}Feeds c
				WHERE
					b.blogid = $blogid AND
					b.blogid = a.blogid AND
					a.id = b.groupId AND
					b.feed = c.id
				ORDER BY RAND()
			";
	$xmlURL = DBQuery::queryAll($query);

	for($i = 0, $URL = ''; $i < count($xmlURL); $i++) {
		if($URL) $URL .= ', ';
		$URL .= '"'.$xmlURL[$i]['xmlURL'].'"';
	}

	$target .= '<div>'.CRLF;
	$target .= '	<h3>'.$title.'</h3>'.CRLF;
	$target .= '	<div style="float:right;margin:'.$reload.'px 5px 0 0;" onclick="'.$category.'.getNext();">'.CRLF;
	$target .= '		<img id="RSSNewsButton_'.$category.'" src="'.$pluginURL.'/image/reload.gif" alt="RSS News Change" style="cursor:pointer;" />'.CRLF;
	$target .= '	</div>'.CRLF;
	$target .= '	<ul id="RSSNewsList_'.$category.'" style="width:100%; overflow:hidden; white-space:nowrap; padding:0;"></ul>'.CRLF;
	$target .= '</div>'.CRLF;

	$target .= '<script type="text/javascript">'.CRLF;
	$target .= '	var pluginURL = "'.$pluginURL.'";'.CRLF;
	$target .= '	var '.$category.' = new __RSSNews("'.$category.'", '.$number.');'.CRLF;
	$target .= '	'.$category.'.setURL('.$URL.');'.CRLF;
	$target .= '	'.$category.'.getNext();'.CRLF;
	$target .= '</script>'.CRLF;

    return $target;
}

function SB_RSSNews_Header($target) {
	global $pluginURL;
	$target .= '<script src="'.$pluginURL.'/RSSNews.js" type="text/javascript"></script>'.CRLF;

	return $target;
}
?>
